<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 300px;
      border: 1px solid #000;
      margin: 0 auto;
      text-align: center;
    }
    .question {
      margin-top: 20px;
      font-size: 20px;
      font-weight: bold;
    }
    .btnBox {
      margin: 30px 0;
      
    }
  </style>
</head>
<body>
  <div class="box">
    <div>随机问答</div>
    <div class="question">问题是：<span style="color: red;">问题1</span></div>
    <div class="btnBox">
      <button class="start">开始抽题</button>
      <button class="stop">停止抽题</button>
    </div>
  </div>
  <script>
    const startBtn = document.querySelector(".start");
    const stopBtn = document.querySelector(".stop");
    const question = document.querySelector(".question span");
    const questions = ["问题1", "问题2", "问题3", "问题4", "问题5"];
    let timer = null;
    let randomIndex = 0;
    startBtn.addEventListener("click", () => {
      startBtn.disabled = true;
      if(questions.length === 0) {
        question.innerText = "没有问题了";
        return;
      }
      timer = setInterval(() => {
      randomIndex = Math.floor(Math.random() * questions.length);
        question.innerText = questions[randomIndex];
      }, 100);
    });
    stopBtn.addEventListener("click", () => {
      clearInterval(timer);   
      startBtn.disabled = false;
      // 抽取的问题不能再出现
      questions.splice(randomIndex, 1);
    });
    
    
  </script>
</body>
</html>